//
//  WYCPersonalCenterController.m
//  51信用卡
//
//  Created by 中企互联 on 2017/11/4.
//  Copyright © 2017年 中企互联. All rights reserved.
//

#import "WYCPersonalCenterController.h"

@interface WYCPersonalCenterController ()<UITableViewDelegate,UITableViewDataSource>

/** 遮盖View*/
@property(nonatomic,strong)UIView * coverView;


/** 显示View*/
@property(nonatomic,strong)UIView * showView;


/** 表视图*/
@property(nonatomic,strong)UITableView * tableView;
@end

@implementation WYCPersonalCenterController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    //Nav
    [self setupNav];
    
    
    //表视图创建
    [self setupTableView];
    
    
    
    
    
}
#pragma make --------->>表视图创建
- (void)setupTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, cellHeight * 5) style:UITableViewStylePlain];
    //    self.tableView.backgroundColor = [UIColor redColor];
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
}
#pragma make --------->>setupNav
- (void)setupNav{
    
    self.view.backgroundColor = WYCGlobalBg;
    self.navigationItem.title = @"个人信息";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.navigationController.navigationBar setBarTintColor:bigredColor];
    
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTitle:@"保存" target:self action:@selector(PreservationClick)];
}

#pragma make -------->>数据代理  数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 4;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 320 * px;
    }else{
        return cellHeight;
    }
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    tableView.tableFooterView = [[UIView alloc] init];
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"123"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"123"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    CGFloat cellXY = 40 * px;
    
    CGFloat celltitle = 80 * px;
    
    if (indexPath.row == 0) {
        UIView * cellView = [[UIView alloc] init];
        cellView.frame = CGRectMake(0, 0, ScreenWidth, cellHeight);
        [cell addSubview:cellView];
        
        
        UILabel * photoLabel = [[UILabel alloc] init];
        photoLabel.frame = CGRectMake(cellXY, cellXY, 150 * px, 240 * px);
        photoLabel.text = @"头像";
        photoLabel.font = [UIFont systemFontOfSize:MiddleFont];
        [cellView addSubview:photoLabel];
        
        
        UIImageView * photoImageView = [[UIImageView alloc] init];
        photoImageView.frame = CGRectMake(cellView.width - cellXY - 240 * px, cellXY, 240 * px, 240 * px);
        photoImageView.backgroundColor = [UIColor redColor];
        photoImageView.layer.masksToBounds = YES;
        [photoImageView setUserInteractionEnabled:YES];
        [photoImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showPictureClick)]];
        photoImageView.layer.cornerRadius = photoImageView.width / 2;
        [cellView addSubview:photoImageView];
        
    }
    else if (indexPath.row == 1){
        UIView * cellView = [[UIView alloc] init];
        cellView.frame = CGRectMake(0, 0, ScreenWidth, cellHeight);
        [cell addSubview:cellView];
        
        
        UILabel * nameLabel = [[UILabel alloc] init];
        nameLabel.frame = CGRectMake(cellXY, cellXY, 150 * px, celltitle);
        nameLabel.text = @"昵称";
        nameLabel.font = [UIFont systemFontOfSize:MiddleFont];
        [cellView addSubview:nameLabel];
        
    }else if (indexPath.row == 2){
        UIView * cellView = [[UIView alloc] init];
        cellView.frame = CGRectMake(0, 0, ScreenWidth, cellHeight);
        [cell addSubview:cellView];
        
        
        UILabel * nameLabel = [[UILabel alloc] init];
        nameLabel.frame = CGRectMake(cellXY, cellXY, 150 * px, celltitle);
        nameLabel.text = @"ID";
        nameLabel.font = [UIFont systemFontOfSize:MiddleFont];
        [cellView addSubview:nameLabel];
        
    }else{
        UIView * cellView = [[UIView alloc] init];
        cellView.frame = CGRectMake(0, 0, ScreenWidth, cellHeight);
        [cell addSubview:cellView];
        
        
        UILabel * nameLabel = [[UILabel alloc] init];
        nameLabel.frame = CGRectMake(cellXY, cellXY, 150 * px, celltitle);
        nameLabel.text = @"手机";
        nameLabel.font = [UIFont systemFontOfSize:MiddleFont];
        [cellView addSubview:nameLabel];
        
    }
    return cell;
}
#pragma make -------->>保存
- (void)PreservationClick{
    WYCLogFunc;
    
}

#pragma make --------->>修改头像
- (void)showPictureClick{
    //遮盖View
    UIView * coverView = [[UIView alloc] init];
    coverView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight - 500 * px);
    coverView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
//    coverView.backgroundColor = bigredColor;
    [[UIApplication sharedApplication].keyWindow addSubview:coverView];
    self.coverView = coverView;
    
    
    
    //选择View
    UIView * photoView = [[UIView alloc] init];
    photoView.frame = CGRectMake(0, ScreenHeight - 500 * px, ScreenWidth, 500 * px);
    photoView.backgroundColor = WYCGlobalBg;
    [self.view addSubview:photoView];
    self.showView = photoView;
    
    
    //拍照按钮
    UIButton * PhotoButton = [[UIButton alloc] init];
    PhotoButton.frame = CGRectMake(0, 0, photoView.width, photoView.height / 3 - 10 * px);
    PhotoButton.backgroundColor = [UIColor whiteColor];
    [PhotoButton setTitle:@"拍照" forState:UIControlStateNormal];
    [PhotoButton setTitleColor:WYZBlackBg forState:UIControlStateNormal];
    [PhotoButton addTarget:self action:@selector(PhotoButtonClick) forControlEvents:UIControlEventTouchUpInside];
    PhotoButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [photoView addSubview:PhotoButton];
    
    
    
    //分割线
    UIView * line = [[UIView alloc] init];
    line.frame = CGRectMake(0, CGRectGetMaxY(PhotoButton.frame), photoView.width, 0.5);
    line.backgroundColor = WYZGrayBg;
    [photoView addSubview:line];
    
    
    //相册按钮
    UIButton * AlbumButton = [[UIButton alloc] init];
    AlbumButton.frame = CGRectMake(0, CGRectGetMaxY(line.frame), photoView.width, photoView.height / 3 - 10 * px);
    AlbumButton.backgroundColor = [UIColor whiteColor];
    [AlbumButton setTitle:@"相册" forState:UIControlStateNormal];
    [AlbumButton setTitleColor:WYZBlackBg forState:UIControlStateNormal];
    [AlbumButton addTarget:self action:@selector(AlbumButtonClick) forControlEvents:UIControlEventTouchUpInside];
    AlbumButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [photoView addSubview:AlbumButton];
    
    
    //相册按钮
    UIButton * cancelButton = [[UIButton alloc] init];
    cancelButton.frame = CGRectMake(0, CGRectGetMaxY(AlbumButton.frame) + 30 * px, photoView.width, photoView.height / 3 - 10 * px);
    cancelButton.backgroundColor = [UIColor whiteColor];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(cancelButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [cancelButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    cancelButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [photoView addSubview:cancelButton];
    
}
#pragma make -------->>拍照按钮
- (void)PhotoButtonClick{
    
    WYCLogFunc;
    self.coverView.hidden = YES;
    self.showView.hidden = YES;
}

#pragma make -------->>相册按钮
- (void)AlbumButtonClick{
     WYCLogFunc;
    self.coverView.hidden = YES;
    self.showView.hidden = YES;
}
#pragma make -------->>取消按钮
- (void)cancelButtonClick{
    WYCLogFunc;
    self.coverView.hidden = YES;
    self.showView.hidden = YES;
}
@end

